package com.jinmdz.fmis.api.admin.controller;

import com.jinmdz.fmis.api.admin.model.servicebusiness.ServiceBusinessCodeData;
import com.jinmdz.fmis.api.admin.model.servicebusiness.ServiceBusinessDataSaveData;
import com.jinmdz.fmis.api.admin.service.ServiceBusinessService;
import com.jinmdz.fmis.api.api.model.common.IdVersionData;
import com.jinmdz.fmis.api.base.BaseController;
import com.jinmdz.fmis.core.base.BaseResult;
import com.jinmdz.fmis.dao.admin.model.servicebusiness.ServiceBusinessDataListItem;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.ArrayList;

/**
 * 业务模块使用物品服务关联关系设置
 *
 * @author GuanKui
 * @date 2020/3/16 13:48
 */
@Api(description = "业务模块使用物品服务关联关系设置")
@RestController()
@RequestMapping("/admin/service-business")
public class ServiceBusinessController extends BaseController {

    @Resource
    private ServiceBusinessService serviceBusinessService;

    /**
     * 根据业务编码加载业务模块下的数据项列表
     *
     * @param data 业务类型
     * @return
     * @author GuanKui
     * @date 2020/3/9  15:05
     */
    @ApiOperation(value = "根据业务编码加载业务模块下的数据项列表", notes = "根据表【service_business_item】中业务编码【business_type】加载业务模块下的数据项列表")
    @PostMapping("/load-service-business-data-list-with-code")
    public BaseResult<ArrayList<ServiceBusinessDataListItem>> loadServiceBusinessDataListWithCode(@RequestBody ServiceBusinessCodeData data) {
        return resultHandler(userItem -> serviceBusinessService.loadServiceBusinessDataListWithCode(data));
    }

    /**
     * 保存业务、费用关联数据信息
     *
     * @param data 关联信息
     * @return
     * @author GuanKui
     * @date 2020/3/16  13:58
     */
    @ApiOperation(value = "保存业务、费用关联数据信息", notes = "保存业务、费用关联数据信息到表【service_business_item】中")
    @PostMapping("/save-service-business-data")
    public BaseResult saveServiceBusinessData(@RequestBody ArrayList<ServiceBusinessDataSaveData> data) {
        return resultHandler(data, userItem -> serviceBusinessService.saveServiceBusinessData(userItem, data));
    }

    /**
     * 删除业务、费用关联数据关联信息
     *
     * @param data 主键和数据版本
     * @return
     * @author GuanKui
     * @date 2020/3/16  13:58
     */
    @ApiOperation(value = "删除业务、费用关联数据关联信息", notes = "从表【service_business_item】中删除业务、费用关联数据关联信息")
    @PostMapping("/delete-service-business-data-with-id")
    public BaseResult deleteServiceBusinessDataWithId(@RequestBody ArrayList<IdVersionData> data) {
        return resultHandler(data, userItem -> serviceBusinessService.deleteServiceBusinessDataWithId(userItem, data));
    }

}

